<?php
/**
 * Get the inventory for current object and parse inventory.tpl.
 *
 * PHP versions 5
 *
 * Copyright (C)
 * This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation. Either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. Without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. Ff not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * Copyright (C) 2006-2007
 *
 * @author Bastian Schröder <bs@chemanet.de>
 * @version 2008-04-11
 * @package railbrowser
 */

function ajax_call( $ajaxBridge ) {
	global $object, $smarty;
	$inventory = array();

	// up
	if( !$object instanceof rail_root )
		$inventory[] = array(
			'id' => $object->get_environment()->get_id(),
			'name' => '..',
			'title' => '',
			'type' => 'up',
			'desc' => '',
			'is_readable' => true
		);

	// inventory
	if( $object->is_readable() )
		foreach( $object->get_inventory() as $inv )
			$inventory[] = array(
				'id' => $inv->get_id(),
				'name' => $inv->get_name(),
				'title' => $inv->get_name(),
				'type' => $inv->get_type(),
				'desc' => $inv->is_readable() ? $inv->get_attribute( OBJ_DESC ) : '',
				'is_readable' => $inv->is_readable(),
				'is_writeable' => $inv->is_writeable()
			);

	// smarty
	$smarty->assign( 'inventory', $inventory );

	// JSON
	$ajaxBridge->append(array(
		'html_code' => $smarty->fetch('inventory.tpl')
	));
}

?>